package io.serializable;

import framework.AbstractTest;
import utils.Log;

import java.io.*;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Created by shane on 2018/5/28.
 */
public class Logon extends AbstractTest implements Serializable {

    private static final String TAG = "Logon";
    private static final long serialVersionUID = 7798038101149966582L;

    private Date date = new Date();
    private String username;
    private transient String password;

    public Logon() {
    }

    public Logon(String username, String password) {

        this.username = username;
        this.password = password;
    }

    @Override
    public String toString() {
        return "logon info: \n username:" + username + "\n date : " + date + "\n password :" +  password;
    }


    @Override
    public void test(String[] args) {
        super.test(args);
        String outPath = getDefTempFile(args);

        try {
            Logon a = new Logon("Hulk ", " myLittlePony");
            Log.vn("logon a = " + a);

            ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(outPath));
            Log.vn("saving objects:");
            o.writeObject(a);
            o.close();

            TimeUnit.SECONDS.sleep(1);

            ObjectInputStream in = new ObjectInputStream(new FileInputStream(outPath));
            Log.vn("recovering objects at:" + new Date());
            a = (Logon) in.readObject();
            Log.vn("logon a = " + a);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected String getTag() {
        return TAG;
    }
}
